 
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  basicprocess.authentication;

import java.util.Hashtable;
import java.util.Vector;

import control.RequestParameter;

import logger.PoolLogger;

import query.view.Condition;
import utility.CapitalChar;
import utility.ConvertToLower;
import utility.Input;
import database.RecordSearch;
import dbmanager.Column;
import dbmanager.GetIdName;



public class Report implements basicprocess.authentication.Authentication
{
	public basicprocess.Authentication authentication;
	String object;
	Hashtable<Object, Object> table =new Hashtable<Object, Object>();
	RecordSearch sr;
	String access;
	String ACCESS="access";
	GetIdName gid;
	String CONDITION="condition";
	String REPORT="report";
	PoolLogger pl;
	
	public Report() 
	{
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
		sr  =new RecordSearch();
	}
	
	public boolean getResult()
	{
		try 
		{
			initializeData();
			query.view.Query query =new query.view.Query();
			query.setReportname(gid.getItem(object));
			query.initPool();			
			Hashtable<Object, Object> table = authentication.MasterMap;
			Vector<Object> Condition = new Vector<Object>();
			Condition.add(table);
			query.SetConditionmap(Condition);
			query.initializeData();
			query.getResult();
			query.setReportMap(table);
			String request1stchar = authentication.req.getProcess().substring(0, 1).toLowerCase();
			access = access.toLowerCase();
			if(query.getbuffer().length>1)
			{
				if(access.contains(request1stchar))
					return false;
				else
					return true;
			}	
			else
				return true;
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		return false;
	}
	
	public void initializeData() 
	{
		table.clear();
		String MasterPath = Input.MASTERREPORTSPATH + object +"//" + object + "_mid" + Input.FILRFORMAT;
		table.put("mid", object);
		table.put("td", "null");
		sr.setConditionMap(table);
		String line[] = sr.getArrayFromResultSet();
		table.clear();
		for(int i=0;i<line.length;i++)
		{
			String splitline[] = line[i].split("\t");
			String value = splitline[Column.pv_index-1];
			if(value.equals("0"))
					value =  splitline[Column.vt_index-1];
				table.put(splitline[Column.pid_index-1], value);
		}
		table = ConvertToLower.convertHashKey(table);
		if(table.containsKey(ACCESS))
		{
			access = table.get(ACCESS).toString();
			access = gid.getItem(access);
			if(access.equals("no$"))
				access = table.get(ACCESS).toString();
		}	
	}
	
	public void setobject(Object object, String obj) 
	{
		authentication = ( basicprocess.Authentication) object;
		//this.database = authentication.database;
		this.gid = new GetIdName();
		CONDITION = gid.getId(CONDITION);
		REPORT = gid.getId(REPORT);
		this.object = obj;
		ACCESS = gid.getId(ACCESS);
	}
	
	public static void main(String[] args) 
	{
		Report report = new Report();
		report.setobject("", "24518");
		report.initializeData();
		report.getResult();
	}


	public void setMasterMap(Hashtable<Object, Object> MasterMap) 
	{
		
	}

	public void setPropertyMap(Vector<Object> PropertyMap) 
	{
		
	}

	public void setRequestParameter(RequestParameter req) 
	{
		
	}

	public void setobject(String obj) 
	{
		
	}

}
